home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ Oct 89 / Z0131-Re Window Menu reci-Oct89 < prev    next >
Encoding:
Text File  |  1989-10-20  |  2.3 KB  |  92 lines  |  [TEXT/GEOL]

  1. Item    0778683                         19-Oct-89        08:48
  2.  
  3. From:   MADA.EUROPE                     MacApp Dev Assoc Europe, E Carrasco
  4.  
  5. To:     MACAPP.TECH$                    MACAPP Tech
  6.  
  7. Sub:    RE-Window Menu recipe
  8.  
  9. From:  Father Vincent
  10.  
  11. To:    MacApp.Tech$
  12.  
  13. Sub:   An improvement to the WindowMenu recipe
  14.        (written on a French BBS, Father Vincent isn't yet on AppleLink, Eric)
  15.  
  16.  
  17. Hi all,
  18.  
  19.     I have implemented the same function in an application with a very
  20. similar method. I have also added a functionnality to change the menu item
  21. when the document title changes. Here is my method.
  22.  
  23. {$S ANonRes}
  24. procedure TMyApplication.ChangeMenuWindowName(var aNewTitle, aOldTitle:
  25. Str255);
  26.     var wMenuHdl:   MenuHandle;
  27.      aName:      Str255;
  28.      item:       integer;
  29.      itemCount:  integer;
  30.      done:       Boolean;
  31. begin
  32.      wMenuHdl := GetMHandle(mWindowMenu);
  33.      if wMenuHdl <> NIL then
  34.          begin
  35.          itemCount := CountMItems(wMenuHdl);
  36.          item := cRegularWMItems;
  37.          done := false;
  38.  
  39.          repeat
  40.           item := item + 1;
  41.           GetItem(wMenuHdl, item, aName);
  42.           if aName = aOldTitle then
  43.               begin
  44.               aName := aNewTitle;
  45.               SetItem(wMenuHdl, item, aName);
  46.               done := true;
  47.               end;
  48.          until done or (item >= itemCount);
  49.          end;
  50. end;
  51.  
  52.  
  53. {$S ANonRes}
  54. PROCEDURE TMyDocument.SetTitle(aTitle: Str255); override;
  55.     { To record the old name of the document when the title changes during a
  56.      "save as" command }
  57. begin
  58.     if fOldTitle = NIL then          { Only for the initialisation time }
  59.      fOldTitle := NewString(aTitle);
  60. end;
  61.  
  62.  
  63. {$S AWriteFile}
  64. PROCEDURE TMyDocument.SavedOn(VAR fileName: Str255; volRefNum: INTEGER);
  65. OVERRIDE;
  66.  
  67.     VAR oldTitle:   Str255;
  68.  
  69. BEGIN
  70.     INHERITED SavedOn(fileName, volRefNum);
  71.  
  72.     { Own stuff }
  73.  
  74.     { Changes the text of the menu item when the name of the document
  75. changes }
  76.  
  77.      { Note fOldTitle is a field of TMyDocument }
  78.  
  79.     if (fOldTitle <> NIL) ë (fileName <> fOldTitleîî) then
  80.      begin
  81.      oldTitle := fOldTitleîî;    { To prevent Heap moving }
  82.      TMyApplication(gApplication).ChangeMenuWindowName(fileName,
  83. oldTitle);
  84.  
  85.      DisposIfHandle(fOldTitle);
  86.      fOldTitle := NewString(fileName);
  87.      end;
  88. END;
  89.  
  90.      Father Vincent
  91.  
  92.